// const componentModules = import.meta.globEager('/src/views/**/*.vue') // 立即引入
const componentModules = import.meta.glob('/src/views/**/*.vue') // 懒加载

import Layout from '/src/components/layout/layout.vue'
// import Hello2 from '/src/views/manage/hello.vue'
import EmptyView from '/src/views/components/empty-view.vue'

/**
 * 路由菜单的说明：
 * co_menu: { label: '后台管理', disabled: false, icon: '', alwaysShow:true, permission: 'permission:*' },
 * 路由中带有 co_menu 属性的被认定为菜单，
 * label: 必选，名字 
 * disabled: 可选，是否禁用，展示出来无法的点击。不填或默认为 false
 * icon：可选，渲染的图标，图标来源图标库`vicons` - @vicons/material (可以选择 vicons 中的其他)
 * alwaysShow：可选，当级联菜单只有一个菜单时，默认会使用子菜单代替父菜单，设置为 false 可以保持级联结构。默认 false
 * permission：可选，菜单需要的权限。不填写则不需要权限。
 */

// 后台管理根路径
const MANAGE_ROOT = import.meta.env.VITE_MANAGE_ROOT
// console.log("MANAGE_ROOT", MANAGE_ROOT)

function _importView(_path){
  return componentModules[`/src/views/${_path}`]
}
function _import(_path){
  return componentModules[`/src/${_path}`]
}

const routes = [
    { path: '/', component: _import("views/components/HelloWorld.vue") },
    { path: '/home', component: _importView("home.vue") },
    { path: '/login', component: _importView("login/login-test.vue") },
    { 
      // path: '/manage', 
      path: MANAGE_ROOT, //  环境变量 VITE_MANAGE_ROOT
      component: Layout, 
      redirect: MANAGE_ROOT + '/index',
      co_menu: {},
      children: [
        { name: 'hello',   path: 'index', 
          component: _importView('manage/hello.vue'),
          co_menu: { label: 'Welcome', disabled: false, icon: '',},
        },
      ]
    },
    { 
      // path: '/manage',
      path: MANAGE_ROOT, //  环境变量 VITE_MANAGE_ROOT
      component: Layout, 
      co_menu: { label: '后台管理', disabled: false, icon: '', alwaysShow:true},
      children: [
        { name: 'RoleManage', path: 'r', 
          component: _importView('manage/role/role.vue'),
          co_menu: { label: '角色管理', disabled: false, icon: '', permission: 'role:menu'},
        },
        { name: 'AdminManage', path: 'a', 
          component: _importView('manage/admin/admin.vue'),
          co_menu: { label: '管理员账户', disabled: false, icon: '', permission: 'admin:menu'},
        },
        { name: 'UserManage', path: 'u', 
          component: _importView('manage/user/user.vue'),
          co_menu: { label: '用户账户', disabled: false, icon: '', permission: 'user:menu'},
        },
        { name: 'PermissionManage', path: 'p', 
          component: _importView('manage/permission/permission.vue'),
          co_menu: { label: '权限管理', disabled: false, icon: '', permission: 'permission:menu'},
        },
        // { name: 'TestManage', path: 't3', 
        //   component: EmptyView,
        //   co_menu: { label:'三级菜单测试' },
        //   children: [
        //     { name: 'TestManage-3-2',   path: 'index2', 
        //       component: _importView('manage/hello.vue'),
        //       co_menu: { label: 'Welcome', disabled: false, icon: '',},
        //     },
        //     { name: 'TestManage-3-3',   path: 'index3', 
        //       component: _importView('manage/hello.vue'),
        //       co_menu: { label: 'Welcome', disabled: false, icon: '',},
        //     }
        //   ]
        // },
      ]
    },
    { 
      path: '/tool',  component: EmptyView,
      children: [
        // 西瓜播放器
        { name: 'XGPlayer',   path: 'xgplayer', 
          component: _importView('front/player/xgplayer.vue'),
        },
        // =======
      ]
    },
    // ========
    // { path: '/manage/333', component: Hello2 },
    // { path: "/404", name: "notFound", component: _importView('home.vue') },
    // {
    //   path: "/:pathMatch(.*)", // 此处需特别注意置于最底部
    //   redirect: "/404",
    // }
  ]

export default routes